<?php
require('includes/top.php');
$question = $_POST["q"];	


$qu=mysql_query("select * from faq where faq='".$question."'");
if(mysql_num_rows($qu) > 0)
{
	header("location:add_faq.php");
	
}
else
{
	$sql="INSERT INTO faq(`faq`) VALUES ('$question')";
	$result=mysql_query($sql);
	if($result)
	 {
		$query=mysql_query("select * from faq where faq='".$question."'");
		$row=mysql_fetch_array($query);
		$faq_id=$row['faq_id'];
		if($_POST["ans1"]!='')
		 { 
			$answer= $_POST["ans1"];
			$sql1=mysql_query("INSERT INTO answers(`faq_id`,`answers`) VALUES ('$faq_id','$answer')");
		 }		
		if($_POST["ans2"]!='')
		 {
			$answer= $_POST["ans2"];
			$sql1=mysql_query("INSERT INTO answers(`faq_id`,`answers`) VALUES ('$faq_id','$answer')");
		 }
		if($_POST["ans3"]!='')
		 {
			$answer= $_POST["ans3"];
			$sql1=mysql_query("INSERT INTO answers(`faq_id`,`answers`) VALUES ('$faq_id','$answer')");
		 }
		 header("location:add_faq.php");
	 }
	 else
	 {
		 echo mysql_error();
	 }

}
ob_flush();
?>
 